import 'package:situation/app/router/router_name.dart';
import 'package:situation/app/theme/app_theme.dart';
import 'package:situation/app/theme/dimens.dart';
import 'package:situation/app/theme/gaps.dart';
import 'package:situation/app/theme/text_theme/default_text_theme.dart';
import 'package:situation/data/request/user_request.dart';
import 'package:situation/data/store/auth_store.dart';
import 'package:situation/resources/assets.dart';
import 'package:situation/widgets/mk_card_container.dart';
import 'package:situation/widgets/mk_list_cell_item.dart';
import 'package:situation/widgets/mk_load_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class UserIndexPage extends StatefulWidget {
  @override
  State<UserIndexPage> createState() => _UserIndexPageState();
}

class _UserIndexPageState extends State<UserIndexPage> {
  final controller = Get.find<UserIndexController>();
  final state = Get.find<UserIndexController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: TDNavBar(
          title: "我",
        ),
        body: ListView(
          children: <Widget>[
            _buildUserInfo(),
            _buildNav(),
          ],
        )
    );
  }

  _buildUserInfo() {
    return Container(
      padding: EdgeInsets.only(
          left: AppTheme.iDefaultPadding,
          top: AppTheme.iDefaultPadding,
          bottom: AppTheme.iDefaultPadding),
      // decoration: BoxDecoration(color: Get.theme.cardColor),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Expanded(
              child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Obx(() => Container(
                    decoration: BoxDecoration(
                        border: Border.all(color: Colors.white, width: 3),
                        borderRadius: BorderRadius.all(Radius.circular(34))),
                    child: CircleAvatar(
                      radius: 34,
                      backgroundImage:
                          NetworkImage(AuthStore.to.getUserAvatar()),
                      foregroundColor: Colors.white,
                    ),
                  )),
              Gaps.hGap16,
              InkWell(
                onTap: controller.toUserInformation,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Obx(() => Text(
                        AuthStore.to.isLogin
                            ? AuthStore.to.profile.nickname!
                            : '请登录',
                        style: defaultTextTheme.titleLarge)),
                    Gaps.vGap5,
                  ],
                ),
              )
            ],
          )),
        ],
      ),
    );
  }

  _buildNav() {
    return MkCardContainer(
      padding: EdgeInsets.symmetric(horizontal: AppTheme.iDefaultPadding / 2),
      margin: EdgeInsets.only(
          top: 0,
          left: AppTheme.iDefaultPadding,
          right: AppTheme.iDefaultPadding),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [



          MkListCellItem(
            textIcon: LoadAssetImage(Assets.userServerAddr, width: 18),
            value: '服务地址设置',
            press: () {
              Get.toNamed(RouterName.serverUrlSetting);
            },
          ),

          MkListCellItem(
            textIcon: LoadAssetImage(Assets.userPermission, width: 18),
            value: '权限管理',
            press: () {
              Get.toNamed(RouterName.userPrivacyPermission);
            },
          ),
          MkListCellItem(
            textIcon: LoadAssetImage(Assets.userUserSetting, width: 18),
            value: '系统设置',
            press: controller.toSystemSetting,
          ),
        ],
      ),
    );
  }

}
